Overview

This document contains information on the R program “ecosystem”, how to download and install these programs, how to set some preferences, an introduction to R Studio, how R works in general, and advice on how to get started learning R.

Programs

  1. R – The programming language. Kinda mandatory.
  2. R Studio – A fantastic interface for coding in R. Might as well be mandatory.
  3. R Commander – A true to form GUI (point and click) for using R. (Optional)
  4. LaTeX – Necessary if you want to create PDF reports.

Download and install R

Download the latest versions of R and R Studio for your flavor of operating system from http://cran.r-project.org/

Install Options: - Don’t use a personal library - Don’t create shortcuts on desktop or startup menu

Download and Install R Studio

Download the latest version R Studio Desktop (Free License) for your flavor of operating system.

If you are having difficulty installing these programs here are links to helpful YouTube video on installing both R and R Studio.

R Studio

Initial Start

When you first (like very first time) open R studio you will see three panels.

Console

The console is the full panel on the left

  • Everytime you launch RStudio, it will have the same text at the top of the console telling you the version of R that you’re running.
  • Below that information is the prompt, > . As its name suggests, this prompt is really a request, a request for a command.
  • Initially, interacting with R is all about typing commands and interpreting the output.
  • These commands and their syntax have evolved over decades (literally) and now provide what many users feel is a fairly natural way to access data and organize, describe, and invoke statistical computations.

The console is where you type commands and have them immediately performed.

Environment

The panel in the upper right contains your workspace (aka Environment)

  • This shows you a list of objects/variables that R has saved.
  • For example here a value of 3 has been assigned to the object a.

Files

The files tab gives you easy access to your files and folders.

Plots

  • When working directly in a R code file, plots that you generate will show up in the panel in the lower right corner.
  • When working in a markdown file or R Notebook, these plots will show up directly inline. More on this later.

Help documents

To check the syntax of any function in R, type ? in front of the function name to pull up the help file.

For example here I typed ?mean to get the help file for the mean function.

These aren’t the most helpful of files at times. We will have an entire workshop devoted to how to get help and translate the less-than-clear error messages that R throws at you all too often.

Script file (a.k.a code file)

  • Most often your R studio window will have 4 panels.
  • The top left is your editor window, where you write code or script, the console is now at the bottom. Sometimes it’s minimized, you can use the boxes in the top right corner of the console window to bring up the console.

Setting Preferences to retain sanity

To avoid some of the most common errors when learning R let’s set some preferences in RStudio.

  1. In RStudio the file menu go to Tools then Global Options.
  2. Uncheck “Restore .RData into workspace at startup” and “Always save history”
  3. Where it says ‘Save workspace to .RData on exit:" Select ’Never’
  4. Click apply then ok.

R packages: How things get done.

Installing R Packages

Packages are sets of predefined code, functions and data sets. They provide additional functionality and goodies beyond what is included when you download Base R.

  • Packages are only installed once per computer ever

  • To install the ggplot2 package type the following command at the prompt > and hit enter to submit the command.

You can install multiple packages at once by combining the list of package names using the collection operator c().

Issues

Sometimes packages don’t install properly. Don’t cry, but it is really annoying.

Things you can do

  • Manually install the package using install.packages() not letting that pop-up window try to automatically install the package.
  • Start R Studio as administrator
  • Load Vanilla r directly (not through R Studio)
  • Turn off any anti-virus scanning software that is running. At least for the duration of the install.

R Commander

Pointing and click your way to success.

Additional setup for R Commander

  • Install via the Rcmdr package.
  • Website: http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/
  • You will need to install Pandoc converter engine if you want to create PDF output as Rcmdr uses the old markdown package which only can create HTML output.

LaTeX: A typesetting software

LaTeX allows you to turn your reports into a nicely formatted PDF document.

  • Install once and forget about it.
  • You can edit Tex files directly in R Studio, a separate tex editor is not necessary.
  • One button compile (including bibtex). That is all.

Download from: https://www.latex-project.org/get/

  • Mac: Only one option
  • Windows: I have had best luck with proTeXt
  • Suck it up and get the full 2Gig download for less headache later.

Learning R

All set up and ready to go?

There are a bajillion ways to learn how to program R. Here are some recommended places to start. Just remember. R is open source. It’s free. Training is not always free, but there are plenty of free resources out there. Often books will have accompanying websites or free PDF’s available.

Need more? Check out the current Data Science course offerings

Check out our Resources page for more.